function y=combine_all(n,m,t)

%COMBINE_ALL generates combinations of species with permutations 
%Syntax: y=combine(n,m)
% --- input arguments ---
% n is the total number of species, it can also be the list of species
% m is the length of the solution
% --- output arguments ---
% y is a vector where each row is one of the permutations
%
% Example:
%
%>> y=combine_all(5,3)
%
%y =
%     1     2     3
%     1     2     4
%     1     2     5
%     1     3     4
%     1     3     5
%     1     4     5
%     2     3     4
%     2     3     5
%     2     4     5
%     3     4     5
%
% The function also works for non-numerical vectors, strings and cell
% arrays can also be used. For example:
%
%>> y=combine_all({'A','B','C','D','E'},3)
%
%y = 
%    'A'    'B'    'C'
%    'A'    'B'    'D'
%    'A'    'B'    'E'
%    'A'    'C'    'D'
%    'A'    'C'    'E'
%    'A'    'D'    'E'
%    'B'    'C'    'D'
%    'B'    'C'    'E'
%    'B'    'D'    'E'
%    'C'    'D'    'E'
%
% LOG:
% first created - Jonas Almeida, almeidaj@musc, Feb 2004

if length(n)==1;n=[1:n];end
N=length(n);
y=[];
c1='for i_1=1:N;';
c2='y=[y;[n(i_1)';
c3='end';
for i=2:m % build code
    c1=[c1,'for i_',num2str(i),'=i_',num2str(i-1),'+1:N;'];
    c2=[c2,',n(i_',num2str(i),')'];
    c3=[c3,';end'];
end
c2=[c2,']];'];
%disp([c1,c2,c3])
eval([c1,c2,c3])
